<?php
declare(strict_types=1);

namespace Service\OrderService;

use Service\BaseService;
use App\Model\BbcModel\OrderExtends;
use App\Model\BbcModel\OrderGoods;
use App\Model\BbcModel\OrderReturn;
use App\Model\BbcModel\Order;

/**
 * 订单中心
 * @author chenshubo
 */
class OrderService extends BaseService
{
    public $user_pay_type=[
        1   => '微信支付',
        2   => '支付宝支付'
    ];
    /**
     * 查询退款订单
     * @param array $sns
     */
    public function queryOrderRefundBySns( array $sns = [] )
    {
        return OrderReturn::instance()
        ->select([
            'id',
            'sn'
        ])
        ->whereIn('sn',$sns)
        ->whereIn('check_status',[0,1,4])
        ->get()
        ->toArray();
    }
    
    /**
     * 查询订单
     * @param array $ids
     */
    public function queryOrderExtendsByIds( array $ids = [] )
    {
        return OrderExtends::instance()
        ->whereIn('order_id',$ids)
        ->get()
        ->toArray();
    }
    
    /**
     * 查询订单商品明细
     * @param array $ids
     */
    public function queryOrderGoodsByOrderIds( array $ids = [] )
    {
        $OrderGoodsTable = OrderGoods::instance()->getTable();
        return OrderGoods::instance()
            ->from("{$OrderGoodsTable} as og")
            ->leftjoin('ly_goods as g','g.id','=','og.goods_id')
            ->whereIn('og.order_id',$ids)
            ->select(['og.*','g.supplier_id','g.high_price','g.high_tax_rate'])
            ->get()->toArray();
    }

    public function queryOrdersBySn(array $sns=[],array $select=['*'])
    {
        return Order::instance()
            ->select($select)
            ->whereIn('sn',$sns)
            ->get()
            ->toArray();
    }
}